﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class FangHao_DAL
    {
        public FangHao_DAL(Context context)
        {
            Context = context;
        }

        public Context Context { get; }

        /// <summary>
        /// 房号添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int FangHaoAdd(FangHao_Model m)
        {
            Context.FangHao_Model.Add(m);
            return Context.SaveChanges();
        }

        /// <summary>
        /// 房号列表
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="CName"></param>
        /// <returns></returns>
        public List<FangHao_Model> FangHaoShow(string? Name,string?CName)
        {
            var m=Context.FangHao_Model.AsQueryable().ToList();
            if(!string.IsNullOrEmpty(Name) )
            {
                m=m.Where(x => x.Name.Contains(Name)).ToList();
            }
            if (!string.IsNullOrEmpty(CName))
            {
                m = m.Where(x => x.CName.Contains(CName)).ToList();
            }
            return m;   
        }

        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="ZT"></param>
        /// <returns></returns>
        public int FangHaoZT(int id,string? ZT)
        {
            var m = Context.FangHao_Model.Find(id);
            m.ZT =ZT;
            return Context.SaveChanges();

        }

    }
}
